package main

import (
	"fmt"
	"time"

	"github.com/robfig/cron"
)

//TestJob 测试任务1
type TestJob struct {
	Key string
}

//Run 测试任务1的支持程序
func (testJob TestJob) Run() {
	for i := 0; i < 10; i++ {
		fmt.Println("testJob1...", testJob.Key, " i:", i)
		time.Sleep(time.Millisecond * 1000)
	}
}

//TestJob2 测试任务2
type TestJob2 struct {
	Key string
}

//Run 测试任务2的支持程序
func (testJob2 TestJob2) Run() {
	fmt.Println("testJob2...", testJob2.Key)
}

func main() {
	c := cron.New()
	spec := "*/1 * * * * ?"
	c.AddJob(spec, TestJob2{Key: "test2"})
	var cx *cron.Cron
	cx = c
	cx.Start()
	time.Sleep(time.Second * 10)
	c.Stop()
	time.Sleep(time.Second * 100)
}
